{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-10-21T00:44:53.590222Z",
     "start_time": "2025-10-21T00:44:53.584842Z"
    }
   },
   "source": [
    "import torch\n",
    "import numpy as np"
   ],
   "outputs": [],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T00:44:53.652044Z",
     "start_time": "2025-10-21T00:44:53.623895Z"
    }
   },
   "cell_type": "code",
   "source": "torch.Tensor([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,50])",
   "id": "1bd156a79944a402",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([ 2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10., 11., 12., 13., 14., 15.,\n",
       "        16., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26., 27., 28., 29.,\n",
       "        30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40., 41., 42., 43.,\n",
       "        44., 45., 46., 47., 48., 50.])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T00:44:53.699013Z",
     "start_time": "2025-10-21T00:44:53.685990Z"
    }
   },
   "cell_type": "code",
   "source": [
    "array = np.arange(12).reshape(3,4)\n",
    "array"
   ],
   "id": "2aeaa11b04137260",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3],\n",
       "       [ 4,  5,  6,  7],\n",
       "       [ 8,  9, 10, 11]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T00:44:55.544169Z",
     "start_time": "2025-10-21T00:44:55.530118Z"
    }
   },
   "cell_type": "code",
   "source": "torch.Tensor(array)",
   "id": "e2e7c6d16fcd1124",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[ 0.,  1.,  2.,  3.],\n",
       "        [ 4.,  5.,  6.,  7.],\n",
       "        [ 8.,  9., 10., 11.]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T00:44:55.872541Z",
     "start_time": "2025-10-21T00:44:55.858465Z"
    }
   },
   "cell_type": "code",
   "source": "torch.empty(5,3)",
   "id": "fcdf91c51e1b12",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[-2.5203e-35,  1.2640e-42,  0.0000e+00],\n",
       "        [ 0.0000e+00,  0.0000e+00,  0.0000e+00],\n",
       "        [ 0.0000e+00,  0.0000e+00,  0.0000e+00],\n",
       "        [ 0.0000e+00,  0.0000e+00,  0.0000e+00],\n",
       "        [ 0.0000e+00,  0.0000e+00,  0.0000e+00]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "创建整型数组",
   "id": "840acce7fdc945dc"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T00:44:56.170510Z",
     "start_time": "2025-10-21T00:44:56.158460Z"
    }
   },
   "cell_type": "code",
   "source": "torch.randint(1,4,(5,3))",
   "id": "8024cdb1051252fd",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[1, 3, 3],\n",
       "        [1, 3, 1],\n",
       "        [3, 2, 1],\n",
       "        [2, 2, 2],\n",
       "        [2, 3, 1]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "张量的方法和属性",
   "id": "595ba85244deffe8"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T00:44:56.542776Z",
     "start_time": "2025-10-21T00:44:56.530623Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t2 = torch.Tensor([[[1]]])\n",
    "t2"
   ],
   "id": "d8618c40bedb9aac",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[1.]]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-21T00:44:56.666149Z",
     "start_time": "2025-10-21T00:44:56.652167Z"
    }
   },
   "cell_type": "code",
   "source": "t2.item()",
   "id": "a2bfeb2b579d3875",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 9
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
